import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
const store = new Vuex.Store({
	state: {
		// 公共参数 状态栏 IOS底部距离等
		COMMON_VAR: {
			website: '博邦BMS',
			integral_name: '积分',
			coin_name: '金币',
			//触发导航条滚动变化阈值
			scrollTop_targe: 50,
			// 隐私权限配置
			permission_config: {
				bluetooth: {
					system: 'bluetoothAuthorized',
					system_platform: 'ios',
					system_tips: '在设置-微信-权限中开启蓝牙权限，以正常使用连接、调试等功能',
					WeChat: 'scope.bluetooth',
					WeChat_tips: '蓝牙权限',
					WeChat_content: '在授权页面中开启蓝牙权限，以正常使用连接、调试等功能',
					WeChat_fail_tips: '蓝牙初始化失败',
				},
				location: {
					system: 'locationAuthorized',
					system_tips: '在设置-微信-权限中开启位置权限，以正常使用扫描周边设备功能',
					WeChat: 'scope.bluetooth',
					WeChat_tips: '位置权限',
					WeChat_content: '在授权页面中开启位置权限，以正常使用扫描周边设备功能',
					WeChat_fail_tips: '位置初始化失败',
				},
			},
			page_check_config: {
				// 校验规则
				head: {
					tips_null: '请上传您的头像',
				},

				name: {
					tips_null: '请输入您的姓名',
					tips_fail: '请输入正确的姓名',
					regular: 'check_name',
				},

				nickname: {
					tips_null: '请输入您的昵称',
				},

				phone: {
					tips_null: '请输入您的联系电话',
					tips_fail: '请输入正确的联系电话',
					regular: 'checkphone',
				},
				pwd: {
					tips_null: '请输入您的密码',
				},
				con_pwd: {
					tips_null: '请确认您的密码',
				},
				contrast_pwd: {
					type: 'contrast_pwd',
					tips_fail: '请保证两次密码填写一致',
				},
				sfz: {
					tips_null: '请输入您的身份证',
					tips_fail: '请输入正确的身份证',
					regular: 'check_sfz',
				},
				ystk: {
					tips_null: '请阅读并同意笆林《用户协议》和《隐私协议》',
				},

				send_code_flag: {
					tips_null: '请发送验证码',
				},
				code: {
					tips_null: '请输入验证码',
					// regular: 'check_sfz'
				},
			},
			pay_way: {
				1: {
					title: 'app微信',
					show_tt: '微信支付',
					type: 'wxpay',
				},
				2: {
					title: '微信公众号',
					show_tt: '微信支付',
					type: 'wxpay',
				},
				3: {
					title: '微信小程序',
					show_tt: '微信支付',
					type: 'wxpay',
				},
				4: {
					title: 'app支付宝',
					show_tt: '支付宝',
					type: 'wxpay',
				},
				5: {
					title: 'H5支付宝',
					show_tt: '支付宝',
					type: 'wxpay',
				},
				6: {
					title: '零钱',
					show_tt: '零钱',
					type: 'wxpay',
				},
				7: {
					title: '积分',
					show_tt: '积分',
					type: 'wxpay',
				},
			},
			BLUETOOTH_DEVICE_LIST: [
				{
					UUID_WRITE_SCREEN: '0000FF02', // 写入指定UUID
					UUID_NOTIFY_SCREEN: '0000FF01', // 监听指定UUID
					UUID_PRIMARY_SERVICE: '0000FF00-0000-1000-8000-00805F9B34FB', // 扫描筛选主服务UUID
					bluetooth_device_type: 'device_battery',
					bluetooth_connect: false,
					bluetooth_reconnect: false, // 重连
					bluetooth_deviceId: '',
					bluetooth_device_mac: '',
					bluetooth_device_name: '-',
					// 芯片类型  0 T1方案 1 凹凸7712 2 新塘松下49522 3 中颖309  4 中颖303 5 集澈DC10XX 6 OZ3714
					bluetooth_chip_type: 0,
					bluetooth_serviceId: '',
					bluetooth_writeCharacteristicId: '',
					bluetooth_notifyCharacteristicId: '',
					bluetooth_device_info: {}, //设备数据名称信号id等
					bluetooth_serverList: [],
					bluetooth_break: 'auto_break',
				},
			],
		},
		// 用户信息
		USER_MSG: {},
		USER_LOGIN: false,
		// 蓝牙设备
		BLUETOOTH_INIT: false,
		BLUETOOTH_DEVICE_CONFIG: {},
		// 页面初始化表单数据
		BLUETOOTH_INIT_FORM: {
			dev_temp: 0,
			bluetooth_device_name: '-',
			index_power: '-',
			index_full_time: '-',
			index_empty_time: '-',
			index_data_refresh_time: '-',
			dev_voltage: '-',
			dev_current: '-',
			dev_capacity: '-',
			BatteryCapacity: 0,
			bluetooth_chip_type: 0,
			dev_circulate: '-',
			index_production_date: '-',
			index_balance_status: [],
			index_balance_status_switch: 0,
			index_balance_status_high: [],
			index_protection_status: [],
			index_protection_status_switch: 0,
			index_protection_status_config: [],
			index_protection_status_list: [],
			index_protection_status_show: [],
			index_temperature_show: [],
			index_software_version: '-',
			dev_lng: 0,
			dev_lat: 0,
			dev_soc: 0,
			dev_id: '-',
			index_FET_control_status: [],
			index_charge_switch: 0,
			index_discharge_switch: 0,
			index_discharge_switch: 0,
			index_discharge_switch: 0,
			current_limiting_switch: 0,
			battery_charge_mode: -1,
			heat_switch: 0,
			current_capacity_unit: 0,
			dev_bunch: '-',
			dev_ntc: 0,
			index_NTC_content: [],
			dev_humidity: 0,
			index_alarm_status: [],
			index_alarm_status_config: [],
			index_alarm_status_list: [],
			index_alarm_status_show: [],
			index_full_charge_capacity: 0,
			dev_capacity_2: 0,
			index_balance_current: 0,
			initialize_nominal_capacity: 0,
			initialize_cycle_capacity: 0,
			capacity_voltage_setting_full_voltage: 0,
			capacity_voltage_setting_empty_voltage: 0,
			initialize_system_consumption: 0,
			information_productionDate: '-',
			information_serialNumber: 0,
			system_setting_cycle_count: 0,
			temperature_setting_charge_high_temperature_protection: 0,
			temperature_setting_charge_high_temperature_recovery: 0,
			temperature_setting_charge_low_temperature_protection: 0,
			temperature_setting_charge_low_temperature_recovery: 0,
			temperature_setting_discharge_high_temperature_protection: 0,
			temperature_setting_discharge_high_temperature_recovery: 0,
			temperature_setting_discharge_low_temperature_protection: 0,
			temperature_setting_discharge_low_temperature_recovery: 0,
			protection_parameters_total_overvoltage_protection: 0,
			protection_parameters_total_overvoltage_recovery: 0,
			protection_parameters_total_undervoltage_protection: 0,
			protection_parameters_total_undervoltage_recovery: 0,
			protection_parameters_overvoltage_protection: 0,
			protection_parameters_overvoltage_recovery: 0,
			protection_parameters_undervoltage_protection: 0,
			protection_parameters_undervoltage_recovery: 0,
			current_setting_charge_overcurrent_protection: 0,
			current_setting_discharge_overcurrent_protection: 0,
			balanced_setting_balance_voltage: 0,
			balanced_setting_balance_accuracy: 0,
			system_setting_current_limit: 0,
			function_setting_switch: 0,
			function_setting_load_detection: 0,
			function_setting_balance: 0,
			function_setting_balance_mode: 0,
			function_setting_led: 0,
			function_setting_led_quantity: 0,
			function_setting_rtc: 0,
			function_setting_fcc_limit: 0,
			function_setting_handshake_enable: 0,
			function_setting_gps: 0,
			function_setting_buzzer_enable: 0,
			function_setting_battery_mode: 0,
			function_setting_current_capacity: 0,
			balanced_setting_enable_balance: [],
			function_setting_temp_1: 0,
			function_setting_temp_2: 0,
			function_setting_temp_3: 0,
			function_setting_temp_4: 0,
			function_setting_temp_5: 0,
			function_setting_temp_6: 0,
			function_setting_temp_7: 0,
			function_setting_temp_8: 0,
			temperature_probe_configuration: [],
			initialize_series_number: 0,
			switch_control_time: 0,
			led_working_time: 0,
			capacity_voltage_setting_80_percent: 0,
			capacity_voltage_setting_60_percent: 0,
			capacity_voltage_setting_40_percent: 0,
			capacity_voltage_setting_20_percent: 0,
			hardware_overvoltage_protection_value: 0,
			hardware_undervoltage_protection_value: 0,
			current_setting_secondary_overcurrent_protection: 0,
			current_setting_secondary_overcurrent_delay: 0,
			current_setting_short_circuit_protection: 0,
			current_setting_short_circuit_delay: 0,
			hardware_over_undervoltage_delay: 0,
			current_setting_short_circuit_recovery_delay: 0,
			temperature_setting_charge_low_temperature_delay: 0,
			temperature_setting_charge_high_temperature_delay: 0,
			temperature_setting_discharge_low_temperature_delay: 0,
			temperature_setting_discharge_high_temperature_delay: 0,
			protection_parameters_total_undervoltage_delay: 0,
			protection_parameters_total_overvoltage_delay: 0,
			protection_parameters_undervoltage_delay: 0,
			protection_parameters_overvoltage_delay: 0,
			current_setting_charge_overcurrent_delay: 0,
			current_setting_charge_overcurrent_recovery_delay: 0,
			current_setting_discharge_overcurrent_delay: 0,
			current_setting_discharge_overcurrent_recovery_delay: 0,
			information_batteryManufacturer: '-',
			bms_encoding_information: '-',
			information_barcode: '-',
			gps_shutdown_voltage: 0,
			gps_shutdown_delay: 0,
			capacity_voltage_setting_90_percent: 0,
			capacity_voltage_setting_70_percent: 0,
			capacity_voltage_setting_50_percent: 0,
			capacity_voltage_setting_30_percent: 0,
			capacity_voltage_setting_10_percent: 0,
			capacity_voltage_setting_100_percent: 0,
			learning_capacity: 0,
			system_setting_capacity_correction_interval: 0,
			BatteryVoltage: 0,
			rated_current: 0,
			maximum_power: 0,
			rated_charging_voltage: 0,
			information_ratedDischargeCurrent: 0,
			information_ratedChargeCurrent: 0,
			rated_discharge_power: 0,
			system_setting_recognition_current: 0,
			system_setting_sleep_time: 0,
			reserve_alarm_parameters: 0,
			information_batteryModel: '-',
			information_bmsAddress: '-',
			information_bmsModel: '-',
			link_resistance_1: '-',
			link_resistance_2: '-',
			link_resistance_3: '-',
			link_resistance_4: '-',
			link_resistance_5: '-',
			link_resistance_6: '-',
			link_resistance_7: '-',
			link_resistance_8: '-',
			link_resistance_9: '-',
			link_resistance_10: '-',
			link_resistance_11: '-',
			link_resistance_12: '-',
			link_resistance_13: '-',
			link_resistance_14: '-',
			link_resistance_15: '-',
			link_resistance_16: '-',
			link_resistance_17: '-',
			link_resistance_18: '-',
			link_resistance_19: '-',
			link_resistance_20: '-',
			link_resistance_21: '-',
			link_resistance_22: '-',
			link_resistance_23: '-',
			link_resistance_24: '-',
			link_resistance_25: '-',
			link_resistance_26: '-',
			link_resistance_27: '-',
			link_resistance_28: '-',
			link_resistance_29: '-',
			link_resistance_30: '-',
			dev_preserve: 0,
			protection_count_charge_overcurrent: 0,
			protection_count_discharge_overcurrent: 0,
			protection_count_single_overvoltage: 0,
			protection_count_single_undervoltage: 0,
			protection_count_charge_high_temperature: 0,
			protection_count_charge_low_temperature: 0,
			protection_count_discharge_high_temperature: 0,
			protection_count_discharge_low_temperature: 0,
			protection_count_total_overvoltage: 0,
			protection_count_total_undervoltage: 0,
			dev_restart: 0,
			voltage_calibration_1: 0,
			voltage_calibration_2: 0,
			voltage_calibration_3: 0,
			voltage_calibration_4: 0,
			voltage_calibration_5: 0,
			voltage_calibration_6: 0,
			voltage_calibration_7: 0,
			voltage_calibration_8: 0,
			voltage_calibration_9: 0,
			voltage_calibration_10: 0,
			voltage_calibration_11: 0,
			voltage_calibration_12: 0,
			voltage_calibration_13: 0,
			voltage_calibration_14: 0,
			dev_max: '-',
			dev_min: '-',
			dev_avg: '-',
			dev_diff: '-',
			index_voltage_chart: [],
			index_voltage_chart_config: {},
		},

		// 写入指令模式
		WRITE_COMMAND_MODE: '',
		WRITE_COMMAND_DATA: {},
		// init edit update
		// 响应指令模式
		RESPONSE_COMMAND_MODE: 'init',

		SCAN_QRCODE_MAC: '',

		// 扫描附近蓝牙设备中
		WORKING_SCAN: false,
		// 支付中
		WORKING_PAY: false,
		// 选择文件中
		WORKING_SELECT_FILE: false,
		// 查看图片中
		WORKING_PREVIEW_IMAGE: false,

		// websocket连接
		WEBSOCKET_CONNECT: false,
		WEBSOCKET_COMMADN_EDIT: false,

		COMMADN_EDIT_TASK_INDEX: -1,
	},
	mutations: {
		update_state_name(state, data) {
			let { state_name, state_value } = data;
			state[state_name] = state_value;
		},
		// 公共设置 通过state_name 分别设置对应的state值
		// 如通过state_name: BLUETOOTH_DEVICE_CONFIG ， USER_MSG
		update_state_config(state, config) {
			let { state_name, data } = config;
			if (Object.keys(data).length > 0) {
				for (var key in data) {
					if (data.hasOwnProperty(key)) {
						Vue.set(state[state_name], key, data[key]);
					}
				}
			} else {
				state[state_name] = {};
			}
		},
	},
	actions: {
		store_set_state({ commit }, data) {
			commit('update_state_name', data);
		},
		store_set_state_config({ commit }, data) {
			commit('update_state_config', data);
		},
	},
	getters: {},
});
export default store;
